<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>展期</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
<style type="text/css">
.layui-btn {
   width: 95px;
}
</style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" id="id">
    <input type="hidden" id="initStatus">
    <input type="hidden" id="upStatus">
    <input type="hidden" id="endTimes">
	<div class="layui-form-item layui-row layui-col-xs12">
       <label class="layui-form-label"><span style="color:red;">*</span>展期日期:</label>
		    <div class="layui-input-block">
			    <input type="text" class="layui-input" id="endTime" lay-verify="date" placeholder="请选择展期日期" lay-key="2">
		    </div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label"><span style="color:red;">*</span>展期费用:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input periodMoney" lay-verify="required|periodMoney"" placeholder="输入所收取的展期费用">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="addBorrow">保存</button>
		</div>
	</div>
</form>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script>
layui.use(['form','layer','laydate'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    laydate.render({
        elem: '#endTime',
        value: getDates('${time}')
    });
    
    function getDates(strDate) {
		var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
			function(a) {
				return parseInt(a, 10) - 1;
			}).match(/\d+/g) + ')');
		getDate(6,date);
	}
    
    function getDate(dayNumber,date){
    	date = date ? date : new Date();
	    var ms = dayNumber * (1000 * 60 * 60 * 24)
	    var newDate = new Date(date.getTime() + ms);
	    $("#endTime").val(formatDate(newDate));
    }
    
    function formatDate(date) {
	    var myyear = date.getFullYear();
	    var mymonth = date.getMonth() + 1;
	    var myweekday = date.getDate();
	    if (mymonth < 10) {
	        mymonth = "0" + mymonth;
	    }
	    if (myweekday < 10) {
	        myweekday = "0" + myweekday;
	    }
	    return (myyear + "-" + mymonth + "-" + myweekday);
	}
    
    form.verify({
    	periodMoney:[
            /^([1-9][0-9]*)+(.[0-9]{1,2})?$/
            ,'格式输入不正确'
           ]
    });
    form.on("submit(addBorrow)",function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post("/admin/borrowlog/insert",{
        	 id : $("#id").val(),
        	 initStatus : $("#initStatus").val(),  
        	 upStatus : $("#upStatus").val(),  
        	 endTime : $("#endTime").val(),  
        	 periodMoney : $(".periodMoney").val(),
        	 record : "展期"
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功");
  	            setTimeout(function(){
  	            	var index = parent.layer.getFrameIndex(window.name);
  	            	parent.layer.close(index);
  	            },3000);  
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })
    
      $(".layui-btn-normal").on("click",function(){
    	  var index = layui.layer.open({
              title : "选择借款人",
              type : 2,
	          area : ["700px","450px"],
	          content : "/admin/borrow/selectlist",
          })
      })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
})

function close_self(){
	window.location.href="/admin/userinfo/showlist";
}
</script>
</body>
</html>